//
//  ModifySecurityViewController.m
//  cityStar
//
//  Created by joyban on 14-12-27.
//  Copyright (c) 2014年 tiny. All rights reserved.
//

#import "ModifySecurityViewController.h"
#import "ChangePasswordViewController.h"
#import "ChangeNowPasswordViewController.h"
#import "OrdinaryCell.h"
#import "BindingPhoneViewController.h"
#import "BindingMailboxViewController.h"
#import "HTDefine.h"
#import "UIColor+FlatUI.h"

NSString *const OrdinaryTableViewCellID = @"OrdinaryCell";

@interface ModifySecurityViewController ()
{
    NSMutableArray *arrayOne;
    NSMutableArray *arrayTwo;
}
@property (weak, nonatomic) IBOutlet UITableView *ModifySecurityTabelView;
@property (weak, nonatomic) IBOutlet UIButton *zhuxiaoBtn;

@end

@implementation ModifySecurityViewController

-(void)viewWillAppear:(BOOL)animated
{
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"修改安全信息";
    arrayOne = [NSMutableArray arrayWithObjects:@"绑定手机",@"修改密码", nil];
    arrayTwo = [NSMutableArray arrayWithObjects:@"修改提现密码",@"修改绑定邮箱", nil];
    [self addBackButton];
    self.ModifySecurityTabelView.bounces = NO;
    self.zhuxiaoBtn.layer.cornerRadius = 4;
    self.view.backgroundColor = kBackgroundColor;
    [self setUpTableViews];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setUpTableViews
{
    [self.ModifySecurityTabelView registerNib:[OrdinaryCell nib] forCellReuseIdentifier:OrdinaryTableViewCellID];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
    {
        return 20;
    }else{
        return 10;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [OrdinaryCell heightOfTableCell];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView * sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 220)] ;
    [sectionView setBackgroundColor:[UIColor colorFromHexCode:@"F6F5F1"]];
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 19, tableView.bounds.size.width, 1)];
    [image setImage:[UIImage imageNamed:@""]];
    if(section ==1 )
    {
        [image setFrame:CGRectMake(0, 9, tableView.bounds.size.width, 1)];
    }
    image.backgroundColor = [UIColor colorFromHexCode:@"ECECEC"];
    [sectionView addSubview:image];
    
    return sectionView;
}

#pragma mark - UITableViewDelegate and UITableViewDataSource

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    OrdinaryCell *OrdinaryCell = [tableView dequeueReusableCellWithIdentifier:OrdinaryTableViewCellID];
    OrdinaryCell.selectionStyle = UITableViewCellSelectionStyleGray;
    if(indexPath.section == 0)
    {
        OrdinaryCell.OrdinaryLabel.text = arrayOne[indexPath.row];
    }else{
        OrdinaryCell.OrdinaryLabel.text = arrayTwo[indexPath.row];
    }
    if(indexPath.row == 0)
    {
        [OrdinaryCell.lineOne removeFromSuperview];
    }else{
        [OrdinaryCell.linTwo removeFromSuperview];
    }
    
    return OrdinaryCell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
    {
        if(indexPath.row == 0)
        {
            BindingPhoneViewController *bindingPhoneViewController = [[BindingPhoneViewController alloc] init];
            [self.navigationController pushViewController:bindingPhoneViewController animated:true];
            
        }else{
            ChangePasswordViewController *changePasswordViewController = [[ChangePasswordViewController alloc] init];
            [self.navigationController pushViewController:changePasswordViewController animated:true];
        }
    }else
    {
        if(indexPath.row == 0)
        {
            ChangeNowPasswordViewController *changeNowPasswordViewController = [[ChangeNowPasswordViewController alloc] init];
            [self.navigationController pushViewController:changeNowPasswordViewController animated:true];
        }else {
            BindingMailboxViewController *bindingMailboxViewController = [[BindingMailboxViewController alloc] init];
            [self.navigationController pushViewController:bindingMailboxViewController animated:true];
        }
    }
    [self.ModifySecurityTabelView reloadData];

}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
